package com.icity.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.icity.entity.Menu;
import com.icity.entity.Role;
import com.icity.entity.RoleUser;
import com.icity.entity.User;
import com.icity.entity.treemenu;
import com.icity.entity.twotreemenu;
import com.icity.entity.system.RoleMenu;
@Mapper
public interface SystemRoleMapper {

	//查询角色
		@Select("<script>"
				+"select * from tbl_statistics_role where 1 = 1 "
				+ "<if test='name != null'>"
				+ " and name like CONCAT('%','${name}','%') "
				+ "</if>"
				
				+ " ORDER BY update_time desc "
				+ "limit #{page},#{limit}"
				+ " </script>")
	List<Role> getroleList(Map<Object, Object> map);
	//查询角色
		@Select("<script>"
				+"select count(id) as count from tbl_statistics_role where 1 = 1 "
				+ "<if test='name != null'>"
				+ " and name like CONCAT('%','${name}','%') "
				+ "</if>"
				
				+ " </script>")
	int getRoleCount(Map<Object, Object> map);
		
		@Select("select count(id) as count from tbl_statistics_role where id = #{id}")
		int getroleCountByName(@Param("id") int id);
		
		@Update("update tbl_statistics_role set name=#{name},"
				+ "update_time=#{update_time},"
			
				+ "where id = #{id}")
		int updateRole(Role role);
		
		@Insert("insert into tbl_statistics_role (unique_code,name,create_time,update_time)"
				+ "values (#{unique_code},#{name},#{create_time},#{update_time})")
		int saveRole(Role role);
		   @Delete("delete from tbl_statistics_role where id = #{id}")
		int deleteRoleById(@Param("id") int id);
		/*   @Select("select * from tbl_statistics_menu where parent_code=0 and status=1")
		List<Menu> select();
		   @Select("select * from tbl_statistics_menu where parent_code=#{unique_code}")
		List<Menu> selecttow(String unique_code);*/
		@Select("select * from tbl_statistics_menu")
		List<Menu> selectone();
		@Select("select * from tbl_statistics_menu where parent_code=#{parent_code} and status=1")
		List<Menu> select(String parent_code);
		@Select("select unique_code as id ,name as label from tbl_statistics_menu where parent_code=#{unique_code}") 
		List<twotreemenu> selecttwo(String unique_code);
		@Insert("insert into tbl_statistics_role_menu (unique_code,role_code,menu_code,create_time,update_time)"
				+ "values (#{unique_code},#{role_code},#{menu_code},#{create_time},#{update_time})")
		int insetrrolemenu(com.icity.entity.RoleMenu roleMenu);
		@Select("select menu_code from tbl_statistics_role_menu where role_code=#{roleId}")
		List<Integer> getrolemenu(String roleId);
		
		
		
}
